<?php
require_once APPPATH . "libraries/simple_html_dom.php";
    
class feed_news extends CI_Controller{
    
    public function index(){
        
        $data = $this->getAutoNewsTitle();
        $this->showfeed($data);
        
    }
    
    function getAutoNewsTitle(){
        $url = "http://sohoa.vnexpress.net/";
        $html = file_get_html($url);
        $wrap_content = "ul[id=news_home] li";
        $data = array();
        $stt = 0;
        foreach ($html->find($wrap_content) as $element){
            $title = $element->find('a[class=txt_link]');
            $summary = $element->find('div[class=news_lead]');
            $url_detail = $title[0]->href;
            $html_detail = file_get_html($url_detail);
            $html_content_news = $html_detail->find('div[id=left_calculator]');
            
            $data['title_news'][$stt] = $url_detail;
            $data['text_news'][$stt] = $title[0]->plaintext;
            $data['summary_news'][$stt] = $summary[0]->plaintext;
            $data['content_news'][$stt] = preg_replace("/<\\/?a(\\s+.*?>|>)/", "", $html_content_news[0]);
            $stt++;
            
            if($stt == 2)
            break;
        }
        
        return $data;
    }
    
}

?>
